package com.note.chh.notebook.Adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.text.format.Formatter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.note.chh.notebook.R;
import com.note.chh.notebook.Uitls.AppUtil;
import com.note.chh.notebook.Uitls.localFile.bean.AudioItem;

import java.util.List;

/**
 * Created by caihuahui on 2018/1/19.
 */

public class MusicAdapter extends BaseQuickAdapter<AudioItem,BaseViewHolder> {

    public MusicAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, AudioItem item) {

        helper.setText(R.id.tv_title,setMusicName(item.getName()))
              .setText(R.id.tv_size, AppUtil.formatMillis(item.getDuration()))
              .setText(R.id.tv_duration,setPlayerName(item.getName()))
              .setImageResource(R.id.iv_image,R.mipmap.mobile_music_default_icon);

    }

    //设置音乐名称
    private String setMusicName(String musicName){
        String name = "";
        String[] titles = musicName.split("-");
        if (titles.length>=1) {
            name = titles[0];
        }else{
            name = musicName;
        }
        return name;
    }

    //设置歌手名称
    private String setPlayerName(String musicName){
        String name = "";
        String[] titles = musicName.split("-");
        if (titles.length>=2) {
            name = titles[1];
        }else{
            name = musicName;
        }
        return name;
    }
}
